<?

//Data loading
GenerateMassReport();
/*
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$pdf->SetTransNo('ND061000001');
$Result = GridList ('ND061000001');
$pdf->GridTable($Result,'ND061000001');
$pdf->Output();
*/

function GenerateMassReport() {
  $DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
  $SQL = "SELECT nobkt FROM ais_memorial WHERE nobkt >= '".GetParam("fromTransNo","")."' AND nobkt<='".GetParam("toTransNo","")."' AND urut=999 order by nobkt ";
  //print $SQL;

  $pdf=new COAPDFReport("P","mm","Letter");
  $pdf->DBConnection($DBConnection->dbc);

  $MyResults = $DBConnection->dbc->get_results($SQL,ARRAY_A);
  if ($MyResults) {
    foreach($MyResults as $row) {
      $pdf->ReadHeader($row["nobkt"]);
      $pdf->AddPage();
      $pdf->GenerateReport();
    }
    $pdf->Output();
  }
}

class COAPDFReport extends PDF {
 /** function COAPDFReport($Page,$Size,$PageMode) {
    parent::PDF($Page,$Size,$PageMode);
    $this->ColumnSize = array(85,30,30,30,30);
    $this->TableName = "tblcoa";
    $this->AddFont('arialn','','arialn.php');
    $this->SetFont('arialn','',10);
    $this->SetLeftMargin(5);
  }**/

  function Header() {
		$this->AddFont('arialn','','arialn.php');
    $this->SetFont('arialn','',10);
      $HeaderSize = array(80,60,25,55);
      $perush = GetCompanyName();
      //$this->Cell($HeaderSize[0],4,$perush,0,0,'L',0);
      $this->Cell($HeaderSize[0],4,"PT. AMPEL JAYA",0,0,'L',0);
      $this->SetFont('arialn','',18);
      if (ereg("TK",$this->HeaderResult->nobkt)) $TransMode = "KAS";
      else $TransMode = "BANK";
      if (ereg("BK|BB",$this->HeaderResult->nobkt))
      $this->Cell($HeaderSize[1],4,"BAYAR $TransMode",0,0,'L',0);
      else
      $this->Cell($HeaderSize[1],4,"TERIMA $TransMode",0,0,'L',0);
      $this->SetFont('arialn','',10);
      $this->Ln();
      $this->Cell($HeaderSize[0],4,GetOfficeLocation(),0,0,'L',0);
      $this->Cell($HeaderSize[1],4,"",0,0,'L',0);
      $this->Cell($HeaderSize[2],4,"NO BUKTI",0,0,'L',0);
      $this->Cell($HeaderSize[3],4,": ".$this->TransNo,0,0,'L',0);
      $this->Ln();
      $this->Cell($HeaderSize[0],4,"",0,0,'L',0);
      $this->Cell($HeaderSize[1],4,"",0,0,'L',0);
      $this->Cell($HeaderSize[2],4,"TGL. MUTASI",0,0,'L',0);
      $this->Cell($HeaderSize[3],4,": ".$this->HeaderResult->tglbkt,0,0,'L',0);
      $this->Ln();
      $this->Cell(30,4,"DITERIMA DARI","LT",0,'L',0);
      $this->Cell(5,4,": ".$this->HeaderResult->debnam,'T',0,'L',0);
      $this->Cell($HeaderSize[2],4,"",'T',0,'L',0);
      $this->Cell($HeaderSize[3],4,"",'TR',0,'L',0);
      $this->Cell(25,4,"",0,0,'L',0);
      $this->Cell(25,4,"VALUTA",0,0,'L',0);
      $this->Cell($HeaderSize[3],4,": ".$this->HeaderResult->curr,0,0,'L',0);
      $this->Ln();
      $this->Cell(30,4,"UNTUK",'LB',0,'L',0);
      $this->Cell(5,4,": ".$this->HeaderResult->uraian,'B',0,'L',0);
      $this->Cell($HeaderSize[2],4,"",'B',0,'L',0);
      $this->Cell($HeaderSize[3],4,"",'BR',0,'L',0);
      $this->Cell(25,4,"",0,0,'L',0);
      $this->Cell(25,4,"KURS",0,0,'L',0);
      $this->Cell($HeaderSize[3],4,": ".FormatNumber($this->HeaderResult->rate),0,0,'L',0);
      $this->Ln();
      $this->Ln();
      $this->Cell(10,4,"NO.",1,0,'C',0);
      $this->Cell(60,4,"URAIAN",1,0,'C',0);
      $this->Cell(25,4,"JUMLAH",1,0,'C',0);
      $this->Cell(20,4,"SKADA",1,0,'C',0);
      $this->Cell(15,4,"UU",1,0,'C',0);
      $this->Cell(20,4,"DEBTUR",1,0,'C',0);
      $this->Cell(20,4,"ORDER",1,0,'C',0);
      $this->Cell(20,4,"REFERENSI",1,0,'C',0);
      $this->Ln();
  }

  function DBConnection ($Conn) {
    $this->DBConnection = $Conn;
  }

  function ReadHeader($TransNo) {
    //Header
    $this->TransNo=$TransNo;
    $SQL = "SELECT *,DATE_FORMAT(tglbkt,'%d/%m/%Y') as tglbkt FROM ais_memorial WHERE nobkt='".$TransNo."' AND urut=999 ";
    $this->HeaderResult = $this->DBConnection->get_row($SQL);

  }

  function GenerateReport() {
    //Detail
    $SQL = "SELECT * FROM ais_memorial WHERE nobkt='".$this->TransNo."' ORDER BY urut";
    $MyResults = $this->DBConnection->get_results($SQL,ARRAY_A);
    foreach ($MyResults as $rows) {
      if ($rows['urut']<>999) {
        $this->Cell(10,4,$rows['urut'].".",'LR',0,'R',0);
        $this->Cell(60,4,$rows['uraian'],'LR',0,'L',0);
        if ($rows['curr']=='IDR')
    $this->Cell(25,4,FormatNumber($rows['jumlah']),'LR',0,'R',0);
    else
    $this->Cell(25,4,FormatNumber($rows['jumlah'],2),'LR',0,'R',0);
        $this->Cell(20,4,$rows['skada'],'LR',0,'C',0);
        $this->Cell(15,4,$rows['kdact'],'LR',0,'C',0);
        $this->Cell(20,4,$rows['debtur'],'LR',0,'C',0);
        $this->Cell(20,4,$rows['noorder'],'LR',0,'C',0);
        $this->Cell(20,4,$rows['noref'],'LR',0,'C',0);
        $this->Ln();
      }
    }   $this->BlankLine();$this->BlankLine();

        $this->Cell(10,4,$rows['urut'].".",1,0,'R',0);
        $this->Cell(60,4,$rows['uraian'],1,0,'L',0);
        if ($rows['curr']=='IDR')
        $this->Cell(25,4,FormatNumber($rows['jumlah']),1,0,'R',0);
    else
        $this->Cell(25,4,FormatNumber($rows['jumlah'],2),1,0,'R',0);
        $this->Cell(20,4,$rows['skada'],1,0,'C',0);
        $this->Cell(15,4,$rows['kdact'],1,0,'C',0);
        $this->Cell(20,4,$rows['debtur'],1,0,'C',0);
        $this->Cell(20,4,$rows['noorder'],1,0,'C',0);
        $this->Cell(20,4,$rows['noref'],1,0,'C',0);
        $this->Ln();
        $terbilang = new intToRupiah();
        $terbilang->setTail($rows['curr']);
        $terbilang->setNumber($rows['jumlah']);


        $this->Cell(120,4,"TERBILANG : ".strtoupper($terbilang->getCurrency()),0,0,'L',0);
        $this->Ln();
        $this->Ln();
  }

  function BlankLine() {
        $this->Cell(10,4,"",'LR',0,'R',0);
        $this->Cell(60,4,"",'LR',0,'L',0);
        $this->Cell(25,4,"",'LR',0,'R',0);
        $this->Cell(20,4,"",'LR',0,'C',0);
        $this->Cell(15,4,"",'LR',0,'C',0);
        $this->Cell(20,4,"",'LR',0,'C',0);
        $this->Cell(20,4,"",'LR',0,'C',0);
        $this->Cell(20,4,"",'LR',0,'C',0);
        $this->Ln();
  }

  function footer() {
      if (ereg("BK|BB",$this->HeaderResult->nobkt)) {
        $this->Cell(65,4,"SETUJU BAYAR",1,0,'C',0);
        $this->Cell(60,4,"PENANGGUNG JAWAB",1,0,'C',0);
        $this->Cell(65,4,"PENERIMA",1,0,'C',0);
      } else {
        $this->Cell(65,4,"SETUJU TERIMA",1,0,'C',0);
        $this->Cell(60,4,"PENYETOR",1,0,'C',0);
        $this->Cell(65,4,"PENERIMA",1,0,'C',0);
      }
        $this->Ln();
        $this->Cell(15,4,"NAMA",1,0,'C',0);
        $this->Cell(50,4,"",1,0,'C',0);
        $this->Cell(15,4,"NAMA",1,0,'C',0);
        $this->Cell(45,4,"",1,0,'C',0);
        $this->Cell(15,4,"NAMA",1,0,'C',0);
        $this->Cell(50,4,"",1,0,'C',0);
        $this->Ln();
        $this->Cell(15,4,"","LR",0,'C',0);
        $this->Cell(50,4,"","LR",0,'C',0);
        $this->Cell(60,4,"","LR",0,'C',0);
        $this->Cell(65,4,"","LR",0,'C',0);
        $this->Ln();
        $this->Cell(15,4,"TANDA","LR",0,'C',0);
        $this->Cell(50,4,"","LR",0,'C',0);
        $this->Cell(60,4,"","LR",0,'C',0);
        $this->Cell(65,4,"","LR",0,'C',0);
        $this->Ln();
        $this->Cell(15,4,"TANGAN","LR",0,'C',0);
        $this->Cell(50,4,"","LR",0,'C',0);
        $this->Cell(60,4,"","LR",0,'C',0);
        $this->Cell(65,4,"","LR",0,'C',0);
        $this->Ln();
        $this->Cell(15,4,"","LRB",0,'C',0);
        $this->Cell(50,4,"","LRB",0,'C',0);
        $this->Cell(60,4,"","LRB",0,'C',0);
        $this->Cell(65,4,"","LRB",0,'C',0);
        $this->Ln();
        $this->Cell(190,4,"",1,0,'C',0);
        $this->Ln();
  }

}

?>
